/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Sir Tam
 */
public class Kho {
    private String MaKho;
    private String TenKho;
    private String DiaChi;
    DBHelper obj =new DBHelper();

    public Kho() {
    }

    public Kho(String MaKho, String TenKho, String DiaChi) {
        this.setMaKho(MaKho);
        this.setTenKho(TenKho);
        this.setDiaChi(DiaChi);
    }

    public String getDiaChi() {
        return DiaChi;
    }

    public void setDiaChi(String DiaChi) {
        this.DiaChi = DiaChi;
    }

    public String getMaKho() {
        return MaKho;
    }

    public void setMaKho(String MaKho) {
        this.MaKho = MaKho;
    }

    public String getTenKho() {
        return TenKho;
    }

    public void setTenKho(String TenKho) {
        this.TenKho = TenKho;
    }

    public DBHelper getObj() {
        return obj;
    }

    public void setObj(DBHelper obj) {
        this.obj = obj;
    }
    public int InsertKho(Kho a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaKho());
            v.add(a.getTenKho());
            v.add(a.getDiaChi());
            
            i=obj.executeUpdate("sp_InsertKho",v);
        }catch(SQLException ex){}
        return i;
    }
    public int UpdateKho(Kho a) throws SQLException
    {
        //DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaKho());
            v.add(a.getTenKho());
            v.add(a.getDiaChi());
            i=obj.executeUpdate("sp_UpdateKho",v);
        }catch(SQLException ex){}
        return i;
    }
    public int DelKho(String MaKho) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(MaKho);            
            i=obj.executeUpdate("sp_DelKho",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public Vector getAllKho() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = obj.executeQuery("sp_getAllKho");
            while(rs.next())
            {                  
                Kho a = new Kho();
                a.setMaKho(rs.getString(1));
                a.setTenKho(rs.getString(2));
                a.setDiaChi(rs.getString(3));
                v.add(a);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
}
